package com.medibooking.gwt.client.calendar.ui.model;

import java.util.Date;


import com.google.gwt.user.datepicker.client.CalendarUtil;
import com.google.inject.Singleton;
import com.medibooking.gwt.client.CalendarConstants;
import com.medibooking.gwt.client.util.CalendarUtils;

/**
 * This class maintains the current state of the calendar. It's used to share
 * state among views and other kind of objects and it's singleton The
 * singletoness of this object is managed by GIN
 * 
 * @author joaomiguel.pereira@gmail.com
 * 
 */
@Singleton
public class CalendarState {

    private Date           startDate      = null;
    private Date           endDate        = null;
    private PeriodLength calendarPeriod = CalendarConstants.DEFAULT_CALENDAR_PERIOD;
    private int            startHour      = CalendarConstants.DEFAULT_STAR_HOUR;
    private int            endHour        = CalendarConstants.DEFAULT_END_HOUR;
    private TimeSlotSize   timeSlotSize   = TimeSlotSize.HALF_HOUR;

    /**
     * Create a new Calendar State
     */
    public CalendarState() {
        this.startDate = calendarPeriod.startDay().equals(CalendarDay.MONDAY) ? CalendarUtils.getLastMondayDate()
                : new Date();
        this.endDate = new Date(this.startDate.getTime());
        CalendarUtil.addDaysToDate(this.endDate, calendarPeriod.numberOfDays());
        

    }

    /**
     * 
     * @return
     */
    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public PeriodLength getCalendarPeriod() {
        return calendarPeriod;
    }

    public void setCalendarPeriod(PeriodLength calendarPeriod) {
        this.calendarPeriod = calendarPeriod;
    }

    public int getStartHour() {
        return startHour;
    }

    public void setStartHour(int startHour) {
        this.startHour = startHour;
    }

    public int getEndHour() {
        return endHour;
    }

    public void setEndHour(int endHour) {
        this.endHour = endHour;
    }

    public TimeSlotSize getTimeSlotSize() {
        return timeSlotSize;
    }

    public void setTimeSlotSize(TimeSlotSize timeSlotSize) {
        this.timeSlotSize = timeSlotSize;
    }

}
